How to unicode Myanmar texts on Java? [closed]

Posted by Spacez Ly Wang on Programmers See other posts from Programmers or by Spacez Ly Wang
Published on 2012-12-20T08:32:56Z Indexed on 2012/12/20 11:12 UTC
Read the original article Hit count: 390

Filed under:
|
|
|
|

I'm just beginner of Java.
I'm trying to unicode (display) correctly Myanmar texts on Java GUI ( Swing/Awt ).
I have four TrueType fonts which support Myanmar unicode texts. There are Myanmar3, Padauk, Tharlon, Myanmar Text ( Window 8 built-in ).
You may need the fonts before the code. Google the fonts, please.
Each of the fonts display on Java GUI differently and incorrectly.

Here is the code for GUI Label displaying myanmar texts:
++++++++++++++++++++++++

package javaapplication1;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class CusFrom {
private static void createAndShowGUI() {
JFrame frame = new JFrame("Hello World Swing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String s = "\u1015\u102F \u103C\u1015\u102F";
JLabel label = new JLabel(s);
label.setFont(new java.awt.Font("Myanmar3", 0, 20));// font insert here, Myanmar Text, Padauk, Myanmar3, Tharlon
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
++++++++++++++++++++++++

Outputs vary. See the pictures:
Myanmar3 IMG
Myanmar 3 Label Output
Padauk IMG
Padauk Label Output
Tharlon IMG
Tharlon Label Output
Myanmar Text IMG
Myanmar Text Label output
What is the correct form? (on notepad)
Correct Form Text
Well, next is the code for GUI Textfield inputting Myanmar texts:
++++++++++++++++++++++++
package javaapplication1;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class XusForm {
private static void createAndShowGUI() {
JFrame frame = new JFrame("Frame Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField textfield = new JTextField();
textfield.setFont(new java.awt.Font("Myanmar3", 0, 20));
frame.getContentPane().add(textfield);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
++++++++++++++++++++++++
Outputs vary when I input keys( unicode text ) on keyboards.
Myanmar Text Output IMG
Myanmar text textfield output
Padauk Output IMG
Padauk textfield output
Myanmar3 Output IMG
Myanmar 3 textfield output
Tharlon Output IMG
Tharlon textfield output
Those fonts work well on Linux when opening text files with Text Editor application.
My Question is how to unicode Myanmar texts on Java GUI. Do I need additional codes left to display well? Or Does Java still have errors? The fonts display well on Web Application (HTML, CSS) but I'm not sure about displaying on Java Web Application.

© Programmers or respective owner

Related posts about java

Related posts about gui